//
//  SDHomeViewController.m
//  Sudoku
//
//  Created by 兰伟欣 on 16/6/12.
//  Copyright © 2016年 wxlan. All rights reserved.
//

#import "SDHomeViewController.h"
#import "SDLevelModel.h"
#import "SDLevelCell.h"
#import "SDLevelDetailController.h"

@interface SDHomeViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *levelArray;

@end

@implementation SDHomeViewController


- (NSMutableArray *)levelArray
{
    if (!_levelArray) {
        _levelArray = [[NSMutableArray alloc] init];
        
    }
    return _levelArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.tableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
    
    for (int i = 0; i < 4; i++) {
        SDLevelModel *levelModel = [[SDLevelModel alloc] init];
        levelModel.allLevel = 1000;
        levelModel.doingLevel = 1;
        levelModel.unsolvedLevel = 999;
        switch (i) {
            case 0:
                levelModel.name = @"Easy";
                break;
            case 1:
                levelModel.name = @"Medium";
                break;
            case 2:
                levelModel.name = @"Hard";
                break;
            case 3:
                levelModel.name = @"Very Hard";
                break;
            default:
                break;
        }
        [self.levelArray addObject:levelModel];
    }
    [self.tableView reloadData];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.levelArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SDLevelCell *levelCell = [SDLevelCell levelCellWithTableView:tableView];
    
    levelCell.levelModel = self.levelArray[indexPath.row];
    

    return levelCell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    [self.navigationController pushViewController:[[SDLevelDetailController alloc] init] animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
